package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.GoodsTypePointsMapper;
import com.gxa.zhonglong.pojo.GoodsTypePoints;
import com.gxa.zhonglong.service.GoodsTypePointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 宸濯
 * Date: 2021/10/30 16:02
 * Description:
 * Version: V1.0
 */
@Service
public class GoodsTypePointsServiceImpl implements GoodsTypePointsService {

    @Autowired
    private GoodsTypePointsMapper goodsTypePointsMapper;
    @Override
    public List<Map<String, Object>> selectByPage(Integer page, Integer size) {
        return goodsTypePointsMapper.selectByPage((page - 1) * size, size);
    }

    @Override
    public Integer selectCount() {
        return goodsTypePointsMapper.selectCount();
    }

    @Override
    public void add(GoodsTypePoints goodsTypePoints) throws BusinessException {
        if (!goodsTypePointsMapper.add(goodsTypePoints)) {
            throw new BusinessException(ExceptionCode.ADD_DEFEATED);
        }
    }

    @Override
    public void update(GoodsTypePoints goodsTypePoints) throws BusinessException {
        if (!goodsTypePointsMapper.update(goodsTypePoints)) {
            throw new BusinessException(ExceptionCode.UPDATE_FALSE);
        }
    }

    @Override
    public void del(Long id) throws BusinessException {
        if (!goodsTypePointsMapper.del(id)) {
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }
}
